package edu.gatech.oad.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;

import edu.gatech.oad.user.Doctor;
import edu.gatech.oad.user.Nurse;
import edu.gatech.oad.user.Patient;
import edu.gatech.oad.user.Receptionist;
import edu.gatech.oad.user.SystemAdministrator;
import edu.gatech.oad.user.User;

public class MenuBar extends JMenuBar{
	private static final long serialVersionUID = 1L;
	private JMenu menu;
	private JMenuItem menuItem;
	private MainPanel mainPanel;
	@SuppressWarnings("unused")
	private UserPanel userPanel; // Will do stuff later
	private JTabbedPane tabbedPane;
	public MenuBar(MainPanel mainPanel, UserPanel userPanel){
		this.mainPanel = mainPanel;
		this.userPanel = userPanel;
		this.tabbedPane = userPanel.getTabbedPane();
		User user = userPanel.getUser();

		
		this.menu = new JMenu("File");
		this.add(menu);

		this.menuItem = new JMenuItem("Save as PDF");
		menu.add(menuItem);
		menuItem.setActionCommand("Save as PDF");
		menuItem.addActionListener(new MenuListener());
		
		menu.addSeparator();
		
		this.menuItem = new JMenuItem("Log Out");
		menu.add(menuItem);
		menuItem.setActionCommand("Log Out");
		menuItem.addActionListener(new MenuListener());
		
		
		
		if(user instanceof Patient) patientMenuBar();
		else if(user instanceof Doctor) doctorMenuBar();
		else if(user instanceof Nurse) nurseMenuBar();
		else if(user instanceof SystemAdministrator) systemAdminMenuBar();
		else if(user instanceof Receptionist) receptionistMenuBar();
	}
	
	private void receptionistMenuBar() {
		// TODO Auto-generated method stub
		
	}

	private void systemAdminMenuBar() {
		this.menu = new JMenu("Users");
		this.add(menu);
		this.menuItem = new JMenuItem("Add Doctor");
		menu.add(menuItem);
		this.menuItem = new JMenuItem("Add Nurse");
		menu.add(menuItem);
		this.menuItem = new JMenuItem("Add Receptionist");
		menu.add(menuItem);
		this.menuItem = new JMenuItem("Add User");
		menu.add(menuItem);
		menuItem.addActionListener(new MenuListener());		
	}

	private void nurseMenuBar() {
		// TODO Auto-generated method stub
		
	}

	private void doctorMenuBar() {
		// TODO Auto-generated method stub
		
	}

	private void patientMenuBar() {
		
	}

	private class MenuListener implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getActionCommand().equals("Log Out")){
				mainPanel.switchToLoginPanel();
				setVisible(false);
			}
			else if (e.getActionCommand().equals("Save as PDF")){
			
			}
		}
	}
}